package com.ysx.server.controller.admin;

import com.github.pagehelper.Page;
import com.ysx.server.pojo.dto.ReportPageQueryDTO;
import com.ysx.server.pojo.entity.Report;
import com.ysx.server.pojo.vo.PageQueryVO;
import com.ysx.server.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/report")
@Slf4j
public class ReportManageController {

    @Autowired
    private ReportService reportService;

    /**
     * 评论分页查询
     * @param reportPageQueryDTO
     * @return
     */
    @GetMapping("/report")
    public PageQueryVO<Report> commentPageQuery(ReportPageQueryDTO reportPageQueryDTO){
        log.info("举报分页查询：{}",reportPageQueryDTO);
        if(reportPageQueryDTO==null){
            return null;
        }
        Page<Report> page = reportService.page(reportPageQueryDTO);
        long total = page.getTotal();
        List<Report> result = page.getResult();
        return new PageQueryVO<Report>(total,result);
    }

    /**
     * 修改评论信息
     * @param report
     * @return
     */
    @PostMapping("/update")
    public boolean updateComment(@RequestBody Report report){
        if(report==null){
            return false;
        }
        return reportService.update(report);
    }

    @GetMapping("/delReport/{id}")
    public boolean delComment(@PathVariable Long id){
        if(id==null||id<0){
            return false;
        }
        return reportService.delComment(id);
    }
}
